package cn.legend.travel.admin.comment.service.impl;

import cn.legend.travel.admin.comment.dao.persist.repository.*;
import cn.legend.travel.admin.comment.pojo.vo.CommentCheckVO;
import cn.legend.travel.admin.comment.service.ICommentService;
import cn.legend.travel.common.enumerator.ServiceCode;
import cn.legend.travel.common.exception.ServiceException;
import cn.legend.travel.common.pojo.vo.PageData;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class CommentServiceImpl implements ICommentService {
    private final ICommentRepository commentRepository;
    @Value("${travel.dao.default-query-page-size}")
    private Integer defaultQueryPageSize;

    @Override
    public PageData<CommentCheckVO> getCommentList(String type, Integer pageNum) {
        return commentRepository.getCommentList(type, pageNum, defaultQueryPageSize);
    }

    @Override
    public void deleteById(String type, Long id) {
        int row = commentRepository.deleteById(type, id);
        if (row != 1) {
            throw new ServiceException(ServiceCode.ERROR_DELETE, "服务器忙,请稍后再试");
        }
    }

    @Override
    public void passById(String type, Long id) {
        int row = commentRepository.passById(type, id);
        if (row != 1) {
            throw new ServiceException(ServiceCode.ERROR_UPDATE, "服务器忙,请稍后再试");
        }
    }
}
